package io.gitee.loulan_yxq.owner.json.test;

import io.gitee.loulan_yxq.owner.core.bean.BeanTool;
import io.gitee.loulan_yxq.owner.core.collection.CollTool;
import io.gitee.loulan_yxq.owner.core.map.MapTool;
import io.gitee.loulan_yxq.owner.json.base.JsonMap;
import io.gitee.loulan_yxq.owner.json.test.domain.User;
import io.gitee.loulan_yxq.owner.json.test.domain.User2;
import io.gitee.loulan_yxq.owner.json.test.domain.UserDate;
import io.gitee.loulan_yxq.owner.json.tool.JSON;
import io.gitee.loulan_yxq.owner.json.tool.JsonTool;
import org.junit.Before;
import org.junit.Test;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.TimeZone;

/*********************************************************
 ** TODO 
 ** <br><br>
 ** Date: Created in 2022/1/19  19:14
 ** @author loulan
 ** @version 0.0.0
 *********************************************************/
public class JsonToolTest2 {
    private User user;
    private List<User> userList;
    private User2 user2;
    private List<User2> user2List;
    private UserDate userDate;

    @Before
    public void init () {
        this.user = new User();
        user.setSex("未知");
        user.setName("xxoo");
        user.setAge(10);

        this.userList = CollTool.list();
        for (int i = 0; i < 150; i++) {
            User userTemp = new User();
            userTemp.setSex("未知");
            userTemp.setName("xxoo");
            userTemp.setAge(i + 12);
            this.userList.add(userTemp);
        }

        this.user2 = new User2();
        user2.setSex("未知");
        user2.setName("xxoo");
        user2.setAge(10);
        user2.setList(userList);

        this.user2List = CollTool.list();
        for (int i = 0; i < 150; i++) {
            User2 userTemp = new User2();
            userTemp.setSex("未知");
            userTemp.setName("xxoo");
            userTemp.setAge(i + 12);
            userTemp.setList(userList);
            this.user2List.add(userTemp);
        }

        this.userDate = new UserDate();
        userDate.setUsername("杨晓强");
        userDate.setAge(12);
        userDate.setBirthday(new Date());
        userDate.setBirthday1(LocalTime.now());
        userDate.setBirthday2(LocalDate.now());
        userDate.setBirthday3(LocalDateTime.now());
    }

    @Test
    public void test01() {
        Map<User, User2> map = MapTool.map();
        map.put(user, user2);

        String json = JSON.toJson(map);
        String userJson = JSON.toJson(user);

        System.out.println(json);
        System.out.println(userJson);
    }

    @Test
    public void test02() {
        long l1 = System.currentTimeMillis();
        List<Map<String, Object>> copy = BeanTool.copy(userList);
        long l2 = System.currentTimeMillis();
        List<JsonMap> jsonMaps = JsonTool.parseListJsonMap(JsonTool.toJson(userList));
        long l3 = System.currentTimeMillis();
        System.out.println(copy);
        System.out.println(jsonMaps);
        System.out.println(l2 - l1);
        System.out.println(l3 - l2);

    }

    @Test
    public void test03() {
        String json = JsonTool.toJson(userDate);
        System.out.println(json);
        String jsonTemp = "{\"username\":\"杨晓强\",\"age\":12,\"birthday\":\"2022-01-20 12:23:56\"}";
        UserDate userDateTemp = JsonTool.parseObj(jsonTemp, UserDate.class);
        System.out.println(userDateTemp);
    }
}
